<?php
/**
 * 交易统计Services
 * User: crstu
 * Date: 2016/6/20
 * Time: 14:32
 */

namespace backend\models\Service;


use common\models\DAO\UserCharge;
use common\models\DAO\UserTradeList;
use common\models\Service\StatsService;

class TradeStatsService extends StatsService
{

    public static function getTradeTotalMoneyByTimeArray($time_array)
    {
        $result = [];
        foreach ($time_array as $k => $v){
            $result[] = UserTradeList::find()->where(['<', 'createTime', $v])->sum('price')/100;
        }
        return $result;
    }

    public static function getTradeTotalCountByTimeArray($time_array){
        $result = [];
        foreach ($time_array as $k => $v){
            $result[] = UserTradeList::find()->where(['<', 'createTime', $v])->sum('count')/100;
        }
        return $result;
    }

    public static function getChargeTotalMoneyByTimeArray($time_array){
        $result = [];
        foreach ($time_array as $k => $v){
            $result[] = UserCharge::find()->where(['typeID' => 1])->andWhere(['<', 'createTime', $v])->sum('money')/100;
        }
        return $result;
    }
}